<template>
	<view class="detail">
		<view class="banner">
			<image :src="pageData.image" mode="" style="width: 750rpx;height: 750rpx;"></image>
		</view>
		<view class="messageBox">
			<view class="title">
				{{pageData.title}}
			</view>
			<view class="time">
				发布时间 {{pageData.created_at}}
			</view>
			<view class="heng"></view>
			<view class="content">
				<rich-text type="text" :nodes="pageData.content"></rich-text>
			</view>
		</view>

	</view>
</template>

<script>
	var graceRichText = require("../../static/richText.js");
	import {
		indexdetail
	} from "@/api/api.js"
	export default {
		data() {
			return {
				pageId: "",
				pageData: {},
			}
		},
		onLoad(options) {
			this.pageId = options.id
			this.handleGetDetail()
		},
		methods: {
			async handleGetDetail() {
				let res = await indexdetail({
					id: this.pageId
				})
				this.pageData = res.data
				this.pageData.content = graceRichText.format(this.pageData.content)
				let _str = this.pageData.content;
				if (_str) {
					let content = _str.replace(/<img[^>]*>/gi, function(match, capture) {
						var match = match.replace(/(width="(.*?)")|(height="(.*?)")/ig, '');
						return match;
					});
					this.pageData.content = content.replace(/< img /g, '< img style="width:100%;height:auto;" ');
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.detail {
		width: 100%;
		min-height: 100%;
		background-color: #ffffff;

		.messageBox {
			padding: 30rpx;
			box-sizing: border-box;

			.title {
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #212121;
				line-height: 37rpx;
			}

			.time {
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #999999;
				line-height: 28rpx;
				margin: 20rpx 0;
			}

			.heng {
				width: 100%;
				height: 1rpx;
				background-color: #EEEEEE;
			}

			.content {
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #666666;
				line-height: 33rpx;
				margin-top: 20rpx;
			}

		}
	}
</style>